<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handlePass"
          :disabled="multiple"
          v-hasPermi="['villagers:review:pass']"
        >通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleFail"
          v-hasPermi="['villagers:review:fail']"
        >作废</el-button>
      </el-col>


      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="houseList" @selection-change="handleSelectionChange" :cell-style="rowStyle">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请编号" align="center" prop="houseId" width="180"/>
      <el-table-column label="申请人姓名" align="center" prop="houseName" />
      <el-table-column label="申请地址" align="center" prop="houseAddress" />
      <el-table-column label="申请单据" align="center" prop="houseDoc" />
      <el-table-column label="申请状态" align="center" prop="houseReviewStatus" :formatter="statusFormat" />
      <el-table-column label="申请日期" align="center" prop="houseDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.houseDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlePass(scope.row)"
            v-hasPermi="['villagers:review:pass']"
          >通过</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleFail(scope.row)"
            v-hasPermi="['villagers:review:fail']"
          >作废</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listHouse, getHouse, passReviews, listReviewHouse, failReviews } from '@/api/villagers/house'
export default {
  name: "House",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      houseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseId: undefined,
        houseName: undefined,
        houseReviewStatus: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        houseDoc: [
          { required: true, message: "单据不能为空", trigger: "blur" }
        ],
        houseName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        houseAddress: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ]
      },

    };
  },
  created() {
    this.getList();
    this.getDicts("sys_housereview_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listReviewHouse(this.queryParams).then(response => {
        this.houseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.houseReviewStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        housePid: undefined,
        houseId: undefined,
        houseName: undefined,
        houseSex: undefined,
        houseNation: "汉族",
        houseReviewStatus: undefined,
        houseAddress: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.houseId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 通过按钮操作 */
    handlePass(row) {
      const houseIds = row.houseId || this.ids;
      this.$confirm('是否确认通过单据编号为"' + houseIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return passReviews(houseIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("已通过");
      }).catch(() => {});
    },

    /** 删除按钮操作 */
    handleFail(row) {
      const houseIds = row.houseId || this.ids;
      this.$confirm('是否确认作废申请编号为"' + houseIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return failReviews(houseIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("已作废");
      }).catch(() => {});
    },

    rowStyle({row, column, rowIndex, columnIndex}){
      //设置表格每行间隔颜色
      if (row.houseReviewStatus ==='0'){
        return "background: oldlace;"
      }
      if (row.houseReviewStatus ==='3'){
        return "background:#ffeded;"
      }
      if (row.houseReviewStatus ==='4'){
        return "background:#f0f9eb;"
      }


    },


  }
};
</script>


